Skip to content

fix: add git worktree support#5

Merged
notkurt merged 4 commits intomainfrom
fix/worktree-support
Mar 16, 2026
Merged

fix: add git worktree support#5
notkurt merged 4 commits intomainfrom
fix/worktree-support

Conversation

@notkurt
Copy link
Owner

@notkurt notkurt commented Mar 16, 2026

Summary

  • Add mainRepoRoot() to resolve the main repo root via git rev-parse --git-common-dir, even when running inside a worktree
  • Session storage (.ai-sessions/), QMD collection naming, git hooks, and knowledge files now always target the main repo root
  • ghost enable from a worktree places config files (.claude/settings.json, .mcp.json) locally but stores everything else in the main repo
  • Document the two approaches for getting hooks into worktrees: commit config files (seamless) or run ghost enable per worktree

Fixes #4

Test plan

  • New src/git.test.tsmainRepoRoot() returns main repo from worktrees, matches repoRoot() in normal repos
  • Worktree tests in src/hooks.test.ts — sessions created/ended/written from worktree stored in main repo
  • Worktree tests in src/setup.test.tsenable from worktree, stable collection names, hooks/gitignore in main repo
  • All 223 tests pass, typecheck and lint clean

🤖 Generated with Claude Code

Kurtis Tozer and others added 4 commits March 17, 2026 09:33
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When running in a git worktree, repoRoot() returns the worktree
directory instead of the main repo root. This causes the QMD
collection name to differ per worktree, ghost status to report
the collection as missing, and .ai-sessions/ to be created inside
the worktree (lost on cleanup).

Add mainRepoRoot() which uses git rev-parse --git-common-dir to
resolve the main repo root. Use it for session storage, QMD
collection naming, and all session/knowledge CLI commands. Keep
repoRoot() for worktree-local config files (.claude/settings.json,
.mcp.json, CLAUDE.md) placed by ghost enable.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Verify that mainRepoRoot() returns the main repo from worktrees,
sessions created from worktrees are stored in the main repo,
collection names are stable across worktrees, and ghost enable
from a worktree places config locally but sessions in the main repo.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add Git Worktrees section to README explaining storage behavior
and the two approaches for getting hooks into worktrees (commit
config files vs run ghost enable per worktree). Note the
implication for Claude Code's automatic worktrees.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@notkurt notkurt mentioned this pull request Mar 16, 2026
@notkurt notkurt merged commit 1f472a2 into main Mar 16, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Worktree support

1 participant